package sanrenxing.dayEnd.backRepertoryTotal.dao;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TATrabsactionSettlement;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TATrabsactionSettlementTwo;

import java.util.List;

/**
 * 功能:ta交易结算数据层接口类
 * 编写者：
 * 日期：2021
 * 版本：1.0
 */
public interface TATrabsactionDao {
    /**
     * 分页查询条件
     * @param start
     * @param rows
     * @param condition
     * @return
     */
    @Select("select f.fundName,t.dataId,c.accName,t.price,t.numbers,t.actMoney sumMoney,t.dates,t.tranType,t.tranStatus from fundSetup f " +
            "join taDataTable t on f.fundId=t.fundId join cashAccount c on t.caId=c.caId " +
            "where 1=1 ${condition} and to_char(t.dates,'yyyy-MM-dd')=to_char(sysdate,'yyyy-MM-dd') and t.tranStatus=-1")
    public List<TATrabsactionSettlementTwo> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);

    /**
     * 按条件统计记录数
     * @param condition 统计条件
     * @return 条件
     */
    @Select("select count(*) from fundSetup f join taDataTable t on f.fundId=t.fundId where 1=1 ${condition}")
    public int count(@Param("condition") String condition);

    /**
     * 根据Ta交易编号删除数据
     * @param dataId Ta交易编号
     * @return 1：删除成功；0：删除失败
     */
    @Delete("delete from taDataTable where dataId=#{dataId}")
    public int delete(@Param("dataId") int dataId);

    /**
     * 修改ta交易结算数据
     * @param taTrabsactionSettlement ta交易结算数据对象
     * @return 1：修改成功；0：修改失败
     */
    @Update("update taDataTable set tranStatus=#{tranStatus} where dataId=#{dataId}")
    public int update(TATrabsactionSettlement taTrabsactionSettlement);

    /**
     * 查询所有ta交易处理数据
     * @return 交ta易处理数据对象集合
     */
    @Select("select * from taDataTable where to_char(dates,'yyyy-MM-dd')=to_char(sysdate,'yyyy-MM-dd') and dataId=#{dataId} and tranStatus=-1")
    public TATrabsactionSettlement findById(@Param("dataId") int dataId);
    /**
     * 从基金设置中取出今日数据
     * @return
     */
    @Select("select fundName,ca.accName,NIF as price,(fundSize/NIF) as numbers,fundSize as sumMoney,sysdate as dates,4 as tranType,-1 as tranStatus from \n" +
            "fundSetup fs join cashAccount ca on fs.caId=ca.caId where to_char(fundTime,'yyyy-MM-dd')=to_char(sysdate,'yyyy-MM-dd') and notes='未入库'")
    public TATrabsactionSettlementTwo fundSetupData();

    /**
     * 结算基金的ta交易数据
     * @return
     */
    @Select("select fundId,0 as dataId,caId,NIF as price,(fundSize/NIF) as numbers,fundSize as sumMoney,sysdate as dates,sysdate as endDate,\n" +
            "4 as tranType,-1 as tranStatus from fundSetup where notes='未入库' and to_char(fundTime,'yyyy-MM-dd')=to_char(sysdate,'yyyy-MM-dd')")
    public TATrabsactionSettlement addFundSetup();

    /**
     * 修改基金库存为已入库
     */
    @Update("update fundSetup set notes='已入库'")
    public void updateFundSetup();
}
